package org.tp8.sampleapp.service.intf;

import java.io.Serializable;

import javax.annotation.security.RolesAllowed;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Use;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.tp8.sampleapp.exc.SampleAppException;
import org.tp8.sampleapp.jaxb.paging.adapter.PageAdapter;
import org.tp8.sampleapp.jaxb.paging.adapter.PageableAdapter;
import org.tp8.sampleapp.model.Course;
import org.tp8.sampleapp.rule.model.RuleModelWrapper;

/**
 * The Interface CourseService.
 */
@Path("/course")
@WebService
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED, use = Use.LITERAL)
@Service("courseService")
public interface CourseService extends Serializable {

	/**
	 * Save.
	 * 
	 * @param t
	 *            the t
	 * @return the course
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	@RolesAllowed(value = { "ROLE_ADD_COURSE", "ROLE_EDIT_COURSE" })
	@WebResult(name = "course")
	@WebMethod(operationName = "save")
	@Path("/save")
	@POST
	@Consumes(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	@Produces(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Course save(Course t) throws SampleAppException;

	/**
	 * Find one.
	 * 
	 * @param id
	 *            the id
	 * @return the course
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	@RolesAllowed(value = { "ROLE_VIEW_COURSE" })
	@WebResult(name = "course")
	@WebMethod(operationName = "findOne")
	@Path("/findone/{id}")
	@GET
	@Consumes(value = { MediaType.APPLICATION_FORM_URLENCODED })
	@Produces(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Course findOne(@PathParam("id") @WebParam(name = "id") Long id)
			throws SampleAppException;

	/**
	 * Find all.
	 * 
	 * @param pageable
	 *            the pageable
	 * @return the page
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	@RolesAllowed(value = { "ROLE_VIEW_COURSE" })
	@WebResult(name = "page")
	@WebMethod(operationName = "findAll")
	@Path("/findall")
	@POST
	@Consumes(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	@Produces(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	@XmlJavaTypeAdapter(PageAdapter.class)
	public Page<Course> findAll(
			@XmlJavaTypeAdapter(PageableAdapter.class) @WebParam(name = "pageable") Pageable pageable)
			throws SampleAppException;

	/**
	 * Find by example.
	 * 
	 * @param pageable
	 *            the pageable
	 * @param example
	 *            the example
	 * @return the page
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	@RolesAllowed(value = { "ROLE_VIEW_COURSE" })
	@WebResult(name = "page")
	@WebMethod(operationName = "findByExample")
	@Path("/findbyexample")
	@POST
	@Consumes(MediaType.MULTIPART_FORM_DATA)
	@Produces(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	@XmlJavaTypeAdapter(PageAdapter.class)
	public Page<Course> findByExample(
			@XmlJavaTypeAdapter(PageableAdapter.class) @Multipart(value = "pageable", type = MediaType.MEDIA_TYPE_WILDCARD) @WebParam(name = "pageable") Pageable pageable,
			@Multipart(value = "course", type = MediaType.MEDIA_TYPE_WILDCARD) @WebParam(name = "course") Course example)
			throws SampleAppException;

	/**
	 * Delete.
	 * 
	 * @param id
	 *            the id
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	@RolesAllowed(value = { "ROLE_DELETE_COURSE" })
	@WebMethod(operationName = "delete")
	@Path("/delete/{id}")
	@DELETE
	@Consumes(value = { MediaType.APPLICATION_FORM_URLENCODED })
	@Produces(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public void delete(
			@PathParam("id") @WebParam(name = "id", partName = "param") Long id)
			throws SampleAppException;

	/**
	 * Validate.
	 * 
	 * @param t
	 *            the t
	 * @return the course
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	@WebResult(name = "result")
	@WebMethod(operationName = "validate")
	@Path("/validate")
	@POST
	@Consumes(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	@Produces(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public RuleModelWrapper validate(Course t) throws SampleAppException;

	/**
	 * Count.
	 * 
	 * @return the count of courses
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	@WebResult(name = "result")
	@WebMethod(operationName = "count")
	@Path("/count")
	@GET
	@Consumes(value = { MediaType.APPLICATION_FORM_URLENCODED })
	@Produces(value = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public long count() throws SampleAppException;

}
